package main;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Hashtable;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
 * This class contains the information for the political sliders
 * @author Bart Machielse and Justin Yu
 *no parametrs
 */
public class PoliticalSliders extends JFrame {
	JPanel pane = new JPanel();
	Player p;

	/**
	 * The base constructor
	 * @param player the player that owns the slider
	 */
	public PoliticalSliders(Player player) {
		super("Political Values");
		
		p = player;
		
		JLabel glabel = new JLabel("Governance:");
		JSlider govt = new JSlider(0, 1000, (int)(p.getPoliticalSystem().getLib()*100));
		JLabel slabel = new JLabel("Social Policy:");
		JSlider society = new JSlider(0, 1000, (int)(p.getPoliticalSystem().getSoc()*100));
		JLabel warn = new JLabel("Remember: Happiness is in your hands!");
		final JLabel hapLevel = new JLabel("Happiness level: " +p.getRes().getHappiness());
		
		Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
		labelTable.put(0, new JLabel("Authoritarian") );
		labelTable.put(500, new JLabel("Neutral") );
		labelTable.put(1000, new JLabel("Liberal") );
		govt.setLabelTable(labelTable);
		
		govt.setMajorTickSpacing(100);
		govt.setMinorTickSpacing(50);
		govt.setPaintTicks(true);
		govt.setPaintLabels(true);
		
		Hashtable<Integer, JLabel> slabelTable = new Hashtable<Integer, JLabel>();
		slabelTable.put(0, new JLabel("Restrictive") );
		slabelTable.put(500, new JLabel("Neutral") );
		slabelTable.put(1000, new JLabel("Free") );
		society.setLabelTable(slabelTable);
		
		society.setMajorTickSpacing(100);
		society.setMinorTickSpacing(50);
		society.setPaintTicks(true);
		society.setPaintLabels(true);		
		
		pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
		pane.add(glabel);
		pane.add(govt);
		pane.add(Box.createVerticalGlue());
		pane.add(slabel);
		pane.add(society);
		pane.add(Box.createVerticalGlue());
		pane.add(warn);
		pane.add(hapLevel);
		
		this.add(pane);
		this.setVisible(true);
		this.setSize(500, 300);
		
		govt.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent arg0) {
				p.getPoliticalSystem().setLib(((JSlider) arg0.getSource()).getValue()/100);
				hapLevel.setText("Happiness level: " +p.getRes().getHappiness());
			}
		});
		
		society.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent arg0) {
				p.getPoliticalSystem().setSoc(((JSlider) arg0.getSource()).getValue()/100);
				hapLevel.setText("Happiness level: " +p.getRes().getHappiness());
			}
		});
		
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				p.polSlider = false;
			}
		});
		
	}

}
